package com.example.spring_java_oj.mapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public class ProblemRedis {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    public List<Object> getProblems(){
        List<Object> problrms = stringRedisTemplate.opsForHash().values("problems");
        return problrms;
    }

    public String getProblem(Integer id){
        String problem = (String) stringRedisTemplate.opsForHash().get("problems", Integer.toString(id));
        return problem;
    }

    public Integer insertAndUpdate(String problem, Integer id){
        stringRedisTemplate.opsForHash().put("problems", Integer.toString(id), problem);
        return 1;
    }

    public Integer insertProblems(Map<String,String> map){
        stringRedisTemplate.opsForHash().putAll("problems", map);
        return 1;
    }

    public Integer delete(Integer id){
        stringRedisTemplate.opsForHash().delete("problems", Integer.toString(id));
        return 1;
    }

}
